#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

double calcFutureValue(double P,double r,double M,int n, int t)
{
	double Fv=0.00; //future value
	
	P = P + M; //Principal = Principal + monthlydeposit
	n = n*t; //Total#ofPeriod = #ofPeriodPerYear * #OfYears

	Fv = P * pow(((1+r)/n),n);

	return Fv;
	
}

void getData(double& Principal,double& interest,double&deposit,int& years, int&times)
{
	cout <<"Please enter the principal(ex.1000.00):";
	cin >> Principal;
	cout << endl;

	cout << "Enter rate of interest (ex. 0.01 for 1%):";
	cin >> interest;
	cout << endl;

	cout << "Enter number of years (ex.12):";
	cin >> years;
	cout << endl;

	cout << "Enter number of months interest compounded per year(ex.monthly is 12):";
	cin >> times;
	cout << endl;

	cout << "Enter monthly deposit (ex.100.00):";
	cin >> deposit;
}

void printStars()
{
	int stars, lines;

	for (lines =1; lines <=2; lines++)
	{
		for (stars=1; stars<=60; stars++)
			cout << '*';
		cout << endl << endl; 
	}
}

void SimpleSavingCalculator()
{
	double Fv; //Future Value
	double r,M; //rate of interest,monthly deposit
	double P; //principal
	int n, t; //number of years; number of times per year

	cout << "Welcome to Simple Saving Calculator BETA\n";
	cout << "Programmed by Sandy Yang\n\n";

	printStars();
	
	bool calculateAgain = true;
	char answer;
	
	while (calculateAgain)
	{
		getData (P,r,M,n,t); //call date function
		
		calcFutureValue(P,r,M,n,t); //call future value calculation function 

		cout <<"Your Final Saving Balance is:$ ";
		cout << fixed << showpoint << setprecision (2) << Fv << endl << endl;

		cout << "Do you want to do it again? (y/n)";
		cin >> answer;		
			
		if (answer != 'y')
			{
				calculateAgain = false;
			}													
	}	

	printStars();

	system("PAUSE");
}
		

    